package com.sk.ccflower.server.common.xmlRpcManager;

import java.io.IOException;
import java.net.URL;
import java.sql.Connection;

import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.webserver.XmlRpcServlet;

import com.sk.ccflower.server.lib.dbUtils.ConnectionPoolManager;

public class MyPropertyHandlerMapping extends PropertyHandlerMapping {
	
	protected Logger m_log;
	XmlRpcServlet mParent = null;
	private ConnectionPoolManager mConnectionPool = null;
	
	public MyPropertyHandlerMapping( XmlRpcServlet _parent, ConnectionPoolManager _dbcp, URL url ) {
		this.m_log = Logger.getLogger( getClass() );
		this.mParent = _parent;
		this.mConnectionPool = _dbcp;
		
		super.setAuthenticationHandler( mParent.getAuthenticationHandler() );
        
		if( mParent.getRequestProcessorFactoryFactory() != null )
            super.setRequestProcessorFactoryFactory( mParent.getRequestProcessorFactoryFactory() );
        
        if( mParent.getTypeConverterFactory() != null )
        	super.setTypeConverterFactory( mParent.getTypeConverterFactory() );
        else
        	super.setTypeConverterFactory( mParent.getXmlRpcServletServer().getTypeConverterFactory() );
        
        super.setVoidMethodEnabled( mParent.getXmlRpcServletServer().getConfig().isEnabledForExtensions() );
        
        try {
        	MyRequestSpecificProcessorFactoryFactory fac = new MyRequestSpecificProcessorFactoryFactory( this.mConnectionPool );
        	super.setRequestProcessorFactoryFactory( fac );
			load( Thread.currentThread().getContextClassLoader(), url );
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlRpcException e) {
			e.printStackTrace();
		}
	}
	
}
